package com.changgou.controller;

import com.changgou.bean.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/redis")
public class RedisController {

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("/tstreis")
    public String tstreis(){
        System.out.println(redisTemplate+"=====");
        redisTemplate.opsForValue().set("wode","12134560");
        String resly = redisTemplate.opsForValue().get("wode") +"";
        redisTemplate.expire("wode",1000, TimeUnit.SECONDS);
        System.out.println(redisTemplate.opsForValue().get("wode"));
        redisTemplate.watch("");
        return resly ;
    }

    @RequestMapping("/getreList")
    public String getreList(){
      ListOperations Userlist= redisTemplate.opsForList();
        User user = new User();
      //  Userlist.leftPushAll("use",user);
        Userlist.range("use",0,-1);
        return null;
    }

    @RequestMapping("/saveRedis")
    public boolean saveRedis(@RequestBody User user){
        ListOperations Userlist= redisTemplate.opsForList();
        Userlist.leftPushAll("use",user);
        Userlist.range("use",0,-1);
        return false;
    }


    @RequestMapping("/subscr")
    public boolean subscr(){

        return false;
    }

}
